***********************************************************************************
* Analysis 1: Who Moves?
* Run discrete-time log-logistic models for everyone
* last modified 2/8/2025
*
***********************************************************************************


clear
capture log close 
set more off

***************
* Directories *
***************

cd "/Users/"

global dofile			=	"./Code/NEW-OEWS"
global matrix_data		=   "./Data/National Employment Matrix"
global oews_data		= 	"./Data/OEWS/all_excel"
global onet_data		= 	"./OccLink/ONET/ONET data/merged"
global cps_data			= 	"./Data/CPS/IPUMS/00015"
global xwalk 			=	"./Data/Crosswalk"
global results 			=	"./Results"
global temp				= 	"./Temp"
global logfile          =   "./Results"


log using "${logfile}/TableE3.log", replace
 
**********************************************
* Table 2 Logistic Model                     *
**********************************************

use "${temp}/cps_2000-2020_wide.dta", replace

* Define who moves

gen move = (occ_t0 != occ_t1)

* Generate annual growth rate variable

gen lograte_t0 = log(1+emp_chng_rate_t0)
gen logprojrate_t0 = log(1+proj_pc_growth_t0/100)

* Rescale the growth variables in terms of 10 percent change

gen emp_pc_growth10_t0 = emp_pc_growth_t0/10
gen proj_pc_growth10_t0 = proj_pc_growth_t0/10

drop if emp_pc_growth_t0 > 400 /* drop outliers about 1.4% dropped*/

* Keep years with OOH data
* Drop individuals in the military (9830) and not in the universe (9999) 

mark good if lograte_t0 !=. & logprojrate_t0 !=. & outlook_gr_t0 != .  & outlook_gr_t1 != . 


* m1: individual variables + 2-year employment change

logit move emp_pc_growth10_t0 /*
*/ i.male ib2.age_gr ib1.race i.hispanic ib1.edu_gr i.year /*
*/ if good == 1  

margins, dydx(emp_pc_growth10_t0) 

* m2: individual variables + 10-year projected growth

logit move proj_pc_growth10_t0  /*
*/ i.male ib2.age_gr ib1.race i.hispanic ib1.edu_gr i.year /*
*/ if good == 1    

margins, dydx(proj_pc_growth10_t0)

* m3: individual variables + projected OOH outlook categories

logit move ib2.outlook_gr_t0  /*
*/ i.male ib2.age_gr ib1.race i.hispanic ib1.edu_gr i.year /*
*/ if good == 1  

margins, dydx(outlook_gr_t0) /*average marginal effects*/
margins outlook_gr_t0 /*Average Adjusted Predictions*/


log close
